<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>

        function delA() {
                    var tr = this.parentNode.parentNode
                    // var name = tr.children[0].innerHTML
                    var name = tr.getElementsByTagName('td')[0].innerHTML
                    var flag = confirm('确认删除' + name + '吗')
                    if (flag) {
                        tr.parentNode.removeChild(tr)
                    }
                    return false
                }
        window.onload = function () {
            var allA = document.getElementsByTagName('a')
            var employeeTable = document.getElementById('employeeTable')
            for (var i = 0; i < allA.length; i++) {
                allA[i].onclick = delA
            }

            addEmpButtn = document.getElementById('addEmpButtn')
            addEmpButtn.onclick = function () {
                var empName = document.getElementById('empName').value
                var email = document.getElementById('email').value
                var salary = document.getElementById('salary').value

                var tr = document.createElement('tr')

                tr.innerHTML = '<td>'+empName+'</td>\n' +
                    '        <td>'+email+'</td>\n' +
                    '        <td>'+salary+'</td>\n' +
                    '        <td><a class="up" href="deleteEmp?id=003">Delete</a></td>'
                // var nametd = document.createElement('td')
                // var emailtd = document.createElement('td')
                // var salarytd = document.createElement('td')
                // var atd = document.createElement('td')
                // var a = document.createElement('a')
                //
                // var nametext = document.createTextNode(empName)
                // var emailtext = document.createTextNode(email)
                // var salarytext = document.createTextNode(salary)
                // var atext = document.createTextNode('Delete')
                //
                //
                // a.appendChild(atext)
                // a.href = 'javascript:;'
                // nametd.appendChild(nametext)
                // emailtd.appendChild(emailtext)
                // salarytd.appendChild(salarytext)
                // atd.appendChild(a)
                //
                // tr.appendChild(nametd)
                // tr.appendChild(emailtd)
                // tr.appendChild(salarytd)
                // tr.appendChild(atd)

                tbody = document.getElementsByTagName('tbody')[0]
                tbody.appendChild(tr)
                // a.onclick = delA
                a = tr.getElementsByTagName('a')[0]
                a.onclick = delA


            }

        }
    </script>
</head>
<body>
<table id="employeeTable">
    <tr>
        <th>name</th>
        <th>email</th>
        <th>salary</th>
        <th>&nbsp;</th>

    </tr>
    <tr>
        <td>tom</td>
        <td>tom@tom.com</td>
        <td>2000</td>
        <td><a class="up" href="deleteEmp?id=001">Delete</a></td>
    </tr>
    <tr>
        <td>Jerry</td>
        <td>Jerry@Jerry.com</td>
        <td>1000</td>
        <td><a class="up" href="deleteEmp?id=002">Delete</a></td>
    </tr>
    <tr>
        <td>Bob</td>
        <td>Bob@Bob.com</td>
        <td>10200</td>
        <td><a class="up" href="deleteEmp?id=003">Delete</a></td>
    </tr>
</table>
<div id="formDiv">
    <h4>添加新员工</h4>
    <table>
        <tr>
            <td class="word">name:</td>
            <td class="inp">
                <input type="text" name="empName" id="empName">
            </td>
        </tr>
        <tr>
            <td class="word">email:</td>
            <td class="inp">
                <input type="text" name="email" id="email">
            </td>
        </tr>
        <tr>
            <td class="word">salary:</td>
            <td class="inp">
                <input type="text" name="salary" id="salary">
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <button id="addEmpButtn" value="abc">
                    Submit
                </button>
            </td>
        </tr>
    </table>
</div>
</body>
</html>